/**
  ******************************************************************************
  * @file    w32f006_tsc.c
  * @author  WeiLink Technology
  * @version V1.0.0
  * @date    09/01/2020
  * @brief   This file contains all the functions prototypes for the TSC firmware
  *          library.
  ******************************************************************************
  * @attention
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, WeiLink Technology SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>&copy; COPYRIGHT WeiLink Technology</center></h2>
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __W32F006_TSC_H
#define __W32F006_TSC_H

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "w32f006.h"

/** @addtogroup W32F006_StdPeriph_Driver
  * @{
  */

/** @addtogroup TSC
  * @{
  */ 
/* Exported types ------------------------------------------------------------*/
/** 
  * @brief  TSC Init structure definition
  */
typedef struct
{
    uint32_t TSC_Discard;           /*!< Specifies the TSC discard value.
                                        This parameter can be a value of @ref TSC_Discard_value */

    uint32_t TSC_Mode;              /*!< Specifies the TSC mode.
                                        This parameter can be a value of @ref TSC_mode */

    uint32_t TSC_DigitalPrediv;     /*!< Specifies the TSC digital prediv.
                                        This parameter can be a value of @ref TSC_Digital_Prediv */
    
    uint32_t TSC_AnalogPrediv;      /*!< Specifies the TSC analog prediv.
                                        This parameter can be a value of @ref TSC_Analog_Prediv */
    
    uint32_t TSC_BiasAdj;           /*!< Specifies the TSC bias adjusting.
                                        This parameter can be a value of @ref TSC_Bias_Adj */
}TSC_InitTypeDef;

/* Exported constants --------------------------------------------------------*/

/** @defgroup TSC_Exported_Constants
  * @{
  */ 

/** @defgroup TSC_Discard_value
  * @{
  */
#define TSC_DISCARD_0                               ((uint32_t)0x00000000)
#define TSC_DISCARD_1                               ((uint32_t)0x00000001)
#define TSC_DISCARD_2                               ((uint32_t)0x00000002)
#define TSC_DISCARD_3                               ((uint32_t)0x00000003)
#define IS_TSC_DISCARD(DISCARD)                    (((DISCARD) == TSC_DISCARD_0) || \
                                                    ((DISCARD) == TSC_DISCARD_1) || \
                                                    ((DISCARD) == TSC_DISCARD_2) || \
                                                    ((DISCARD) == TSC_DISCARD_3))
/**
  * @}
  */

/** @defgroup TSC_mode
  * @{
  */
#define TSC_MODE_POLL                               ((uint32_t)0x00000100)
#define TSC_MODE_SCAN                               ((uint32_t)0x00000010)

#define IS_TSC_MODE(MODE)                          (((MODE) == TSC_MODE_POLL) || \
                                                    ((MODE) == TSC_MODE_SCAN))
/**
  * @}
  */

/** @defgroup TSC_Bias_Adj
  * @{
  */
#define IS_TSC_BIAS_ADJ(ADJ)                        ((ADJ) < 16)
/**
  * @}
  */

/** @defgroup TSC_Digital_Prediv
  * @{
  */
#define IS_TSC_DIGITAL_PREDIV(DIV)                  ((DIV) < 0x10)
/**
  * @}
  */

/** @defgroup TSC_AnalogPrediv
  * @{
  */
#define IS_TSC_ANALOG_PREDIV(DIV)                   ((DIV) < 0x10)
/**
  * @}
  */

/** @defgroup TSC_ENABLE_PIO
  * @{
  */
#define IS_TSC_ENABLE_PIO(PIO)                      (((PIO) != 0) && ((PIO) & 0x7FFFF))
/**
  * @}
  */

/** @defgroup TSC_IO
  * @{
  */
#define TSC_IO_PIO0_0                       ((uint32_t)0x00000001)
#define TSC_IO_PIO0_1                       ((uint32_t)0x00000002)
#define TSC_IO_PIO0_2                       ((uint32_t)0x00000004)
#define TSC_IO_PIO0_3                       ((uint32_t)0x00000008)
#define TSC_IO_PIO0_4                       ((uint32_t)0x00000010)
#define TSC_IO_PIO0_5                       ((uint32_t)0x00000020)
#define TSC_IO_PIO0_6                       ((uint32_t)0x00000040)
#define TSC_IO_PIO0_7                       ((uint32_t)0x00000080)
#define TSC_IO_PIO1_0                       ((uint32_t)0x00000100)
#define TSC_IO_PIO1_1                       ((uint32_t)0x00000200)
#define TSC_IO_PIO1_2                       ((uint32_t)0x00000400)
#define TSC_IO_PIO1_3                       ((uint32_t)0x00000800)
#define TSC_IO_PIO1_4                       ((uint32_t)0x00001000)
#define TSC_IO_PIO1_5                       ((uint32_t)0x00002000)
#define TSC_IO_PIO1_6                       ((uint32_t)0x00004000)
#define TSC_IO_PIO1_7                       ((uint32_t)0x00008000)
#define TSC_IO_PIO2_0                       ((uint32_t)0x00010000)
#define TSC_IO_PIO2_1                       ((uint32_t)0x00020000)
#define TSC_IO_PIO2_2                       ((uint32_t)0x00040000)
#define TSC_IO_PIO2_3                       ((uint32_t)0x00080000)
#define IS_TSC_GET_SAMPLE_VALUE_IO(IO)     (((IO) == TSC_IO_PIO0_0) || ((IO) == TSC_IO_PIO0_1) || \
                                            ((IO) == TSC_IO_PIO0_2) || ((IO) == TSC_IO_PIO0_3) || \
                                            ((IO) == TSC_IO_PIO0_4) || ((IO) == TSC_IO_PIO0_5) || \
                                            ((IO) == TSC_IO_PIO0_6) || ((IO) == TSC_IO_PIO0_7) || \
                                            ((IO) == TSC_IO_PIO1_0) || ((IO) == TSC_IO_PIO1_1) || \
                                            ((IO) == TSC_IO_PIO1_2) || ((IO) == TSC_IO_PIO1_3) || \
                                            ((IO) == TSC_IO_PIO1_4) || ((IO) == TSC_IO_PIO1_5) || \
                                            ((IO) == TSC_IO_PIO1_6) || ((IO) == TSC_IO_PIO1_7) || \
                                            ((IO) == TSC_IO_PIO2_0) || ((IO) == TSC_IO_PIO2_1) || \
                                            ((IO) == TSC_IO_PIO2_2) || ((IO) == TSC_IO_PIO2_3))

#define IS_TSC_SET_THRESHOLD_VALUE_IO(IO)  (((IO) == TSC_IO_PIO0_0) || ((IO) == TSC_IO_PIO0_1) || \
                                            ((IO) == TSC_IO_PIO0_2) || ((IO) == TSC_IO_PIO0_3) || \
                                            ((IO) == TSC_IO_PIO0_4) || ((IO) == TSC_IO_PIO0_5) || \
                                            ((IO) == TSC_IO_PIO0_6) || ((IO) == TSC_IO_PIO0_7) || \
                                            ((IO) == TSC_IO_PIO1_0) || ((IO) == TSC_IO_PIO1_1) || \
                                            ((IO) == TSC_IO_PIO1_2) || ((IO) == TSC_IO_PIO1_3) || \
                                            ((IO) == TSC_IO_PIO1_4) || ((IO) == TSC_IO_PIO1_5) || \
                                            ((IO) == TSC_IO_PIO1_6) || ((IO) == TSC_IO_PIO1_7) || \
                                            ((IO) == TSC_IO_PIO2_0) || ((IO) == TSC_IO_PIO2_1) || \
                                            ((IO) == TSC_IO_PIO2_2) || ((IO) == TSC_IO_PIO2_3))
                                            
#define IS_TSC_SET_THRESHOLD_VALUE(VALUE)  (((VALUE) != 0) && ((VALUE) < 32768))

#define IS_TSC_GET_FLAG_IO(IO)             (((IO) == TSC_IO_PIO0_0) || ((IO) == TSC_IO_PIO0_1) || \
                                            ((IO) == TSC_IO_PIO0_2) || ((IO) == TSC_IO_PIO0_3) || \
                                            ((IO) == TSC_IO_PIO0_4) || ((IO) == TSC_IO_PIO0_5) || \
                                            ((IO) == TSC_IO_PIO0_6) || ((IO) == TSC_IO_PIO0_7) || \
                                            ((IO) == TSC_IO_PIO1_0) || ((IO) == TSC_IO_PIO1_1) || \
                                            ((IO) == TSC_IO_PIO1_2) || ((IO) == TSC_IO_PIO1_3) || \
                                            ((IO) == TSC_IO_PIO1_4) || ((IO) == TSC_IO_PIO1_5) || \
                                            ((IO) == TSC_IO_PIO1_6) || ((IO) == TSC_IO_PIO1_7) || \
                                            ((IO) == TSC_IO_PIO2_0) || ((IO) == TSC_IO_PIO2_1) || \
                                            ((IO) == TSC_IO_PIO2_2) || ((IO) == TSC_IO_PIO2_3))

/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void TSC_Init(TSC_InitTypeDef* TSC_InitStruct);
void TSC_DeInit(void);
void TSC_Cmd(uint32_t PIO, FunctionalState NewState);
void TSC_SetMode(uint32_t Mode);
uint16_t TSC_GetSampleValue(uint32_t TSC_IO);
void TSC_SetThresholdValue(uint32_t TSC_IO, uint32_t Value);
FlagStatus TSC_GetFlagStatus(uint32_t TSC_IO);
void TSC_ITConfig(FunctionalState NewState);
ITStatus TSC_GetITStatus(void);
void TSC_ClearITPendingBit(void);

#ifdef __cplusplus
}
#endif

#endif /* W32F006_TSC_H */

/**
  * @}
  */ 

/**
  * @}
  */ 

/**
  * @}
  */ 

/******************* (C) COPYRIGHT WeiLink Technology *****END OF FILE****/
